package q73_setZeroes;

import CommonClass.Common;

public class Solution_1 {
    public static void main(String[] args) {
        Solution_1 s = new Solution_1();
        int[][] arr1 = new int[][]{{1,1,1}, {1,0,6},{1,1,1}};
        s.setZeroes(arr1);

        Common c = new Common();
        c.printMatrix(arr1);


    }


    /**
     * 可以用两个数组记录在i行j列所出现的0，然后再遍历一遍全部置0即可
     * @param matrix
     */
    public void setZeroes(int[][] matrix) {
        int[] m = new int[matrix.length], n = new int[matrix[0].length];

        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[0].length; j++) {
                if (matrix[i][j] == 0) {
                    m[i] = n[j] = 1;
                }
            }
        }

        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[0].length; j++) {
//                if (m[i] == 1 || n[j] == 1) {
//                    matrix[i][j] = 0;
//                }

                if (m[i] + n[j] > 0) {
                    matrix[i][j] = 0;
                }
            }
        }

    }
}
